# ICEMGenerator - 高效的ICEM CFD网格划分Replay Script生成工具
# 案例说明：创建肋片组

import os
from ICEMGenerator import create_rectangle, create_cubic, Part, Block, replay_all, init_all_Id

init_all_Id(0)

# 定义肋片尺寸
count = 10  #肋片数量
bold = 0.003  #肋片厚度
interval = 0.1 / count - bold  #肋片间隔
total_length = bold * count + interval * (count - 1)

# 创建几何对象
srfs = []
left_crvs = []
right_crvs = []
# (1)创建底座（顶面镂空）
base = create_cubic(0, total_length, 0, 0.06, 0, 0.02, front_filled = False, name = 'FINS')
# (2)创建肋片（底面镂空）和肋片之间的凹面
fins = [None] * count
concaves = [None] * (count - 1)
for i in range(count):
    x0 = i * 0.1 / count  #肋片背面的x坐标
    x1 = x0 + bold  #肋片正面的x坐标
    x2 = x1 + interval  #下一个肋片背面的x坐标
    fins[i] = create_cubic(x0, x1, 0, 0.06, 0.02, 0.05, back_filled = False, name = 'fin%d' % i)
    if i <= count - 2:
        concaves[i] = create_rectangle(x1, x2, 0, 0.06, 0.02, axis = 'z', name = 'concave%d' % i)
base.addSurface(concaves)
base.join(fins)
base.setAsFinal()

# 给定边界条件
solid = Part((base,), 'SOLID', 'SOLID')
wall = Part.wallFromRemainSurfaces()

# 创建块
FIN = Block(parts_inside = (solid,), parts_boundary = (wall,), name = 'FIN', dimension = 3, max_element_size = 0.001)

# 一键输出Replay Script
f = open('fins.rpl', 'w')
f.write(replay_all('E:/python/ICEMGenerator/demo/fins', 'fin'))
f.close()
os.system('notepad fins.rpl')